//
// Created by PC on 2023/3/2.
// 计算前N个数的斐波那契数列之和
//

#include <iostream>

using namespace std;

int fibonacci(int n)
{
    if (n == 1)
    { return 1; }
    else if(n == 2)
    { return 2; }
    int cur = 2;
    printf("1 1 %d ",cur);
    int per = 1;
    int sum=4;
    for (int i = 4; i <=n; ++i)
    {
        int t = cur;
        cur=per+cur;
        printf("%d ",cur);
        per = t;
        sum+=cur;
    }
    return sum;
}

int main()
{
    int num = 9;
    printf("\nsum = %d\n",fibonacci(num));
    return 0;
}